//
//  JPSearchView.swift
//  JPWeibo
//
//  Created by 哇咔咔 on 16/9/19.
//  Copyright © 2016年 jp. All rights reserved.
//

import UIKit

class JPSearchView: UIView {

    @IBOutlet weak var searchButton: UIButton!
    
    @IBOutlet weak var searchTextField: UITextField!
    
    @IBOutlet weak var trailingConstraint: NSLayoutConstraint!
    
    class func searchView() -> JPSearchView {
        
        let searchView = UINib(nibName: "JPSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last as! JPSearchView
        
        return searchView
    }
    
    @IBAction func editingDidBeiginAnimation(_ sender: AnyObject) {
        
        trailingConstraint.constant = searchButton.width
        UIView.animate(withDuration: 0.5) {
            self.layoutIfNeeded()
        }
        
    }
    
    @IBAction func clickToSearch(_ sender: AnyObject) {
        
        trailingConstraint.constant = 0
        searchTextField.resignFirstResponder()
        UIView.animate(withDuration: 0.5) {
            self.layoutIfNeeded()
        }
        
    }

}
